package com.lsk.util;

import java.util.HashMap;
import java.util.Map;

public class TianyandataUtil {

    private static final String appId = "NIdjTD8MYPRNnukp";
    private static final String appSecurity = "NIdjTD8MYPRNnukpmAkGRgeTBDjyHGyG";

    public static TianyanResult checkIdCard(String name, String idCard) {
        String timestamp = System.currentTimeMillis() + "";
        //参数
        //接口地址
        String url = "https://api.shumaidata.com/v4/id_card/check";
        //请下载MD5Utils文件,地址为 https://file.tianyandata.cn/demo/utils/MD5Utils.java
        String sign = MD5Utils.encrypt(appId+"&"+timestamp+"&"+appSecurity);
        System.out.println("sign: "+sign);

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("appid",appId);
        params.put("timestamp",timestamp);
        params.put("sign",sign);
        params.put("name", name);
        params.put("idcard", idCard);
        //请下载 HttpUtils文件，地址为 https://file.tianyandata.cn/demo/utils/HttpUtils.java
        String result = HttpUtils.get(url,null,params);
        Syslog.error("调用天眼数聚身份验证接口。name: " + name + "; idCard: " + idCard + "; Result: " + result);

        return SerializeUtil.deserialize(result, TianyanResult.class);
    }

    public static void main(String[] args) {
        String jsonStr = "{\"msg\":\"成功\",\"success\":true,\"code\":200,\"data\":{\"result\":0,\"order_no\":\"342398620045697292\",\"desc\":\"一致\",\"sex\":\"男\",\"birthday\":\"19891210\",\"address\":\"安徽省阜阳市颍上县\"}}";
        TianyanResult tianyanResult = SerializeUtil.deserialize(jsonStr, TianyanResult.class);
        System.out.println(tianyanResult);
    }
}
